<?php
    /**
     * CronRun.php
     *
     * Created by PhpStorm.
     * author: liuml  <liumenglei0211@163.com>
     * DateTime: 2018/7/28  13:51
     */

    namespace app\behavior;

    use think\Exception;
    use think\Response;

    class CronRun
    {
        public function run(&$dispatch){
            $host_name = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : "*";
            $headers = [
                "Access-Control-Allow-Origin" => $host_name,
                "Access-Control-Allow-Credentials" => 'true',
                "Access-Control-Allow-Headers" => "requesttime,sign"
            ];
            if($dispatch instanceof Response) {
                $dispatch->header($headers);
            } else if($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
                $dispatch['type'] = 'response';
                $response = new Response('', 200, $headers);
                $dispatch['response'] = $response;
            }
        }
    }